package demo.command;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * 内存溢出模拟
 * -Xms10m -Xmx10m -XX:+HeapDumpOnOutOfMemoryError
 *
 * @author zheng9feng
 * @date 2021/5/11 9:25
 */
public class OOMDemo {
	
	
	public static void main(String[] args) throws InterruptedException {
		try {
			List<Container> containers = new ArrayList<>();
			for (int i = 0; i < 10; i++) {
				TimeUnit.SECONDS.sleep(1);
				System.out.println("i=" + i);
				containers.add(new Container());
			}
			
			System.out.println(containers);
		} catch (InterruptedException e) {
			e.printStackTrace();
			System.out.println("----");
		}
	}
	
	static class Container {
		private final byte[] _1MB = new byte[1024 * 1024];
	}
}
